<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        @include('common.meta')
        <meta name="csrf-token" content="{{ csrf_token() }}">
        @include('common.script')
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>权限名</label>
                        <div class="layui-input-block">
                            <input type="text" id="L_username" name="per_name" required="" lay-verify="per_name" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>权限路由</label>
                        <div class="layui-input-block">
                            <input type="text" id="L_username" name="per_url" required="" lay-verify="per_url" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">增加</button></div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer','jquery'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //自定义验证规则
                form.verify({
                    per_name: function(value) {
                        if (value.length < 1) {
                            return '权限名至少得1个字符';
                        }
                    },
                    per_url: function(value) {
                        if (value.length < 1) {
                            return '权限路由不可为空';
                        }
                    },
                });

                //监听提交
                form.on('submit(add)',
                function(data) {
                    //发异步，把数据提交给php
                    $.ajax({
                        url:'/admin/permission',
                        type:'POST',
                        dataType:'json',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        data:data.field,
                        success:function (res){
                            // 判断
                            if(res.code == 1){
                                layer.msg(res.message,{icon:1},function (){
                                    parent.location.reload(true)
                                })
                            }else {
                                layer.msg(res.message,{icon:5})
                            }
                        },
                        error:function (res){
                        }
                    });
                    return false;
                });

            });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>